package com.kaidi.dibankecloud.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Random;

/**
 * Created by Administrator on 2017/1/9.
 */

public class ResourceUtils {
    /**
     * 按行读取txt
     */
    public static String readTextFromAssets(InputStream is){
        InputStreamReader reader = new InputStreamReader(is);
        BufferedReader bufferedReader = new BufferedReader(reader);
        StringBuffer buffer = new StringBuffer("");
        String str;
        try {
            while ((str = bufferedReader.readLine()) != null) {
                buffer.append(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer.toString();
    }

    /**
     * 生成一个随机四位数用于验证邮箱
     */
    public static String generateFourNumbers(){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0;i < 4;i ++){
            int nextInt = random.nextInt(10);
            sb.append(String.valueOf(nextInt));
        }
        return sb.toString();
    }
}
